package com.myk.game.gobangchess.ai.shock;

public class Findwinpoint {

    public static int[] findwinpoint(int[][] board, int playerTurn) {
        int[] pointSet = {0, 0};

        for (int x = 0; x < 8; x++) {
            for (int y = 0; y < 8; y++) {
                if (board[y][x] == 0) {
                    int[][] boardNew1 = copyBoard(board);
                    boardNew1[y][x] = playerTurn;
                    int[] canWin1 = Winningtest_only1.winningtest_only1(boardNew1);

                    if (canWin1[(int) (0.5 * (1 - playerTurn))] == 1) {
                        pointSet = new int[]{x, y};
                    } else {
                        int[][] boardNew2 = Pointsetting.pointsetting(boardNew1, x, y);
                        int[] canWin2 = Winningtest_only1.winningtest_only1(boardNew2);

                        if (canWin2[(int) (0.5 * (1 - playerTurn))] == 1) {
                            pointSet = new int[]{x, y};
                        }
                    }
                }
            }
        }

        return pointSet;
    }

    private static int[][] copyBoard(int[][] board) {
        int[][] copy = new int[board.length][board[0].length];
        for (int i = 0; i < board.length; i++) {
            for (int j = 0; j < board[0].length; j++) {
                copy[i][j] = board[i][j];
            }
        }
        return copy;
    }
}
